ALTER PROCEDURE [dbo].[CPP_GameKindItem]
  @dwUserID INT,
  @szResult NVARCHAR(255) OUTPUT  -- 输出信息
AS
BEGIN

  -- 获取渠道游戏或用户游戏, 优先级: 用户游戏>渠道游戏


	DECLARE @Channel INT = 0
	SELECT @Channel = Channel FROM RYAccountsDB.dbo.AccountsInfo WHERE AccountsType = 0 AND UserID = @dwUserID
  IF @@ROWCOUNT=0 BEGIN
    SET @szResult = N'玩家[' + CAST(@dwUserID AS NVARCHAR) + ']不存在';
    RETURN 1
  END

	PRINT '{UserID:' + CAST(@dwUserID AS NVARCHAR) + ', Channel:' + CAST(@Channel AS NVARCHAR) + '}'

  -- 渠道号判断
  DECLARE @State INT = 0
  SELECT @State = State FROM RYPlatformDB.dbo.GameChannel WHERE ID = @Channel
  IF @@ROWCOUNT=0 BEGIN
    SET @szResult = N'渠道[' + CAST(@Channel AS NVARCHAR) + ']不存在';
    RETURN 1
  END
  IF @State<>1 BEGIN
    SET @szResult = N'渠道[' + CAST(@Channel AS NVARCHAR) + ']未启用';
    RETURN 2
  END


  PRINT '暂未处理玩家专属小游戏'


  -- 渠道小游戏
	SELECT
		a.Channel,
		c.KindID,
		d.KindName,
		a.ServerID,
		c.ServerType,
		c.ServerName,
		ISNULL(b.Version, 0) AS Version,
		(CASE c.ServerType WHEN 16 THEN ISNULL(e.RoomCard, 0) ELSE 0 end) AS RoomCard
	FROM
	GameChannelRoom AS a
	LEFT JOIN GameRoomInfo AS c ON a.ServerID = c.ServerID AND c.Nullity = 0
	LEFT JOIN GameKindItem AS d ON c.KindID = d.KindID AND d.Nullity = 0
	LEFT JOIN GameChannelKind AS b ON b.Channel = a.Channel AND b.KindID = c.KindID AND b.State = 1
	LEFT JOIN RYTreasureDB.dbo.UserRoomCard e ON e.KindID = c.KindID AND e.UserID = @dwUserID
	WHERE	a.State = 1 AND a.Channel = @Channel


  IF @@ROWCOUNT <= 0 BEGIN
		SET @szResult = N'渠道[' + CAST(@Channel AS NVARCHAR) + ']无小游戏';
    RETURN 5
  END ELSE BEGIN
		SET @szResult = 'SUCCESS'
    RETURN 0
  END

END